package com.ruoyi.system.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.BackUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Frontreport;
import com.ruoyi.system.service.IFrontreportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * frontreportController
 * 
 * @author lbb
 * @date 2022-10-04
 */
@RestController
@RequestMapping("/system/frontreport")
public class FrontreportController extends BaseController
{
    @Autowired
    private IFrontreportService frontreportService;

    /**
     * 查询frontreport列表
     */
    @PreAuthorize("@ss.hasPermi('system:frontreport:list')")
    @GetMapping("/list")
    public TableDataInfo list(Frontreport frontreport)
    {
        startPage();
        List<Frontreport> list = frontreportService.selectFrontreportList(frontreport);
        return getDataTable(list);
    }

    /**
     * 导出frontreport列表
     */
    @PreAuthorize("@ss.hasPermi('system:frontreport:export')")
    @Log(title = "frontreport", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Frontreport frontreport)
    {
        List<Frontreport> list = frontreportService.selectFrontreportList(frontreport);
        ExcelUtil<Frontreport> util = new ExcelUtil<Frontreport>(Frontreport.class);
        util.exportExcel(response, list, "frontreport数据");
    }

    /**
     * 获取frontreport详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:frontreport:query')")
    @GetMapping(value = "/{reportid}")
    public AjaxResult getInfo(@PathVariable("reportid") Long reportid)
    {
        return AjaxResult.success(frontreportService.selectFrontreportByReportid(reportid));
    }

    /**
     * 新增frontreport
     */
    @PreAuthorize("@ss.hasPermi('system:frontreport:add')")
    @Log(title = "frontreport", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Frontreport frontreport)
    {
        return toAjax(frontreportService.insertFrontreport(frontreport));
    }

    /**
     * 修改frontreport
     */
    @PreAuthorize("@ss.hasPermi('system:frontreport:edit')")
    @Log(title = "frontreport", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Frontreport frontreport,@RequestBody BackUser backUser)
    {
        System.out.println("---------------------------------------");
        System.out.println(" 获取后台用户为id:"+backUser.getUserId());
        System.out.println("=========================================");
//        //修改医护人员状态
        backUser.setWork("1");
        frontreportService.updateSysUser(backUser);
//        //修改派遣的医护人员
        frontreport.setR1("105");
        frontreport.setDoc(backUser.getUserId()+"");
        System.out.println("获取到后台用户id"+frontreport.getDoc());
        return toAjax(frontreportService.updateFrontreport(frontreport));
    }

    /**
     * 删除frontreport
     */
    @PreAuthorize("@ss.hasPermi('system:frontreport:remove')")
    @Log(title = "frontreport", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportids}")
    public AjaxResult remove(@PathVariable Long[] reportids)
    {
        return toAjax(frontreportService.deleteFrontreportByReportids(reportids));
    }
}
